<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 300px;
            height: 300px;
            background-color: red;
        }
    </style>
</head>
<!-- 首先得到鼠标在页面中的坐标
其次得到盒子距离body的距离
相减 -->

<body>
    <div class="box"></div>
    <script>
        var box = document.querySelector('.box');
        box.addEventListener('click', function (e) {

            console.log(e.pageX - this.offsetLeft);

        })
    </script>
</body>

</html>